drop table if exists test;

{% for create_command in ['create table test (id UInt64, a Tuple(b Tuple(c UInt32, d String, e Array(UInt32))), data String, index idx1 a.b.c type minmax, index idx2 a.b.d type minmax, index idx3 a.b.c || a.b.d type minmax) engine=MergeTree order by tuple() settings min_rows_for_wide_part=100000000, index_granularity=1;',
                          'create table test (id UInt64, a Tuple(b Tuple(c UInt32, d String, e Array(UInt32))), data String, index idx1 a.b.c type minmax, index idx2 a.b.d type minmax, index idx3 a.b.c || a.b.d type minmax) engine=MergeTree order by tuple() settings min_rows_for_wide_part=1, min_bytes_for_wide_part=1, vertical_merge_algorithm_min_columns_to_activate=10, vertical_merge_algorithm_min_rows_to_activate=10000000, index_granularity=1;',
                          'create table test (id UInt64, a Tuple(b Tuple(c UInt32, d String, e Array(UInt32))), data String, index idx1 a.b.c type minmax, index idx2 a.b.d type minmax, index idx3 a.b.c || a.b.d type minmax) engine=MergeTree order by tuple() settings min_rows_for_wide_part=1, min_bytes_for_wide_part=1, vertical_merge_algorithm_min_columns_to_activate=1, vertical_merge_algorithm_min_rows_to_activate=1, index_granularity=1;'] -%}

select '{{ create_command }}';

{{ create_command }}

system stop merges test;
insert into test select number, tuple(tuple(number, 'str_' || number, range(number % 10))), 'Hello, World!' from numbers(4);
insert into test select number, tuple(tuple(number, 'str_' || number, range(number % 10))), 'Hello, World!' from numbers(4, 4);

select * from test where a.b.c < 2 order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c < 2) where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.d < 'str_2' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.d < 'str_2') where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.c < 2 and a.b.d < 'str_1' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c < 2 and a.b.d < 'str_1') where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.c || a.b.d < '2str_2' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c || a.b.d < '2str_2') where explain not like '%Expression%' and explain not like '%Filter%';

system start merges test;
optimize table test final;
select count() from system.parts where active and table = 'test' and database = currentDatabase();

select * from test where a.b.c < 2 order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c < 2) where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.d < 'str_2' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.d < 'str_2') where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.c < 2 and a.b.d < 'str_1' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c < 2 and a.b.d < 'str_1') where explain not like '%Expression%' and explain not like '%Filter%';
select * from test where a.b.c || a.b.d < '2str_2' order by all;
select trimLeft(explain) from (explain indexes=1 select * from test where a.b.c || a.b.d < '2str_2') where explain not like '%Expression%' and explain not like '%Filter%';

drop table test;

{% endfor -%}

